package net.xxcxcxcx.xc_enhancedmob.packet.damage_num;

import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.xxcxcxcx.xc_enhancedmob.packet.CustomNbtPacket;

public class DamageNumPacket {
    public static void sendDamageNum(Entity entity, float damage, String damageTpye) {
        if (damage >= 0.01f && damage <= 1e+20f) {
            NbtCompound nbtCompound = new NbtCompound();
            nbtCompound.putInt("entity", entity.getEntityId());
            nbtCompound.putFloat("amount", damage);
            nbtCompound.putString("DamageType", damageTpye);
            NbtCompound nbt = new NbtCompound();
            nbt.put("DamageNum", nbtCompound);
            for (ServerPlayerEntity player : PlayerLookup.tracking(entity)) {
                player.networkHandler.sendPacket(CustomNbtPacket.creat(entity.getEntityId(), nbt));
            }
        }
    }
}
